//
//  SimpleShare.m
//  ChiChiFan
//
//  Created by leidian on 15/8/6.
//  Copyright (c) 2015年 mumuxinxinCompany. All rights reserved.
//

#import "SimpleShare.h"

@implementation SimpleShare
{

}

+ (id<ISSShareActionSheet>)shareWithContent:(NSString *)content
       pngImageUrlString:(NSString *)pngImageUrlString
                   title:(NSString *)title
                     url:(NSString *)callBackUrlString
                  sender:(id) sender;
{
    //构造分享内容
    id<ISSContent> publishContent = [ShareSDK content:[NSString stringWithFormat:@"%@\r\n%@", content, callBackUrlString]
                                       defaultContent:@""
                                                image:[ShareSDK imageWithUrl:pngImageUrlString]
                                                title:title
                                                  url:callBackUrlString
                                          description:NSLocalizedString(@"TEXT_TEST_MSG", @"分享")
                                            mediaType:SSPublishContentMediaTypeNews];
    
    //定制QQ空间信息
    [publishContent addQQSpaceUnitWithTitle:title
                                        url:callBackUrlString
                                       site:nil
                                    fromUrl:nil
                                    comment:nil
                                    summary:content
                                      image:[ShareSDK imageWithUrl:pngImageUrlString]
                                       type:[NSNumber numberWithInt:4]
                                    playUrl:nil
                                       nswb:nil];
    
    //定制微信好友信息
    [publishContent addWeixinSessionUnitWithType:[NSNumber numberWithInt:SSPublishContentMediaTypeNews]
                                         content:content
                                           title:title
                                             url:callBackUrlString
                                      thumbImage:nil
                                           image:[ShareSDK imageWithUrl:pngImageUrlString]
                                    musicFileUrl:nil
                                         extInfo:nil
                                        fileData:nil
                                    emoticonData:nil];
    
    //定制微信朋友圈信息
    [publishContent addWeixinTimelineUnitWithType:[NSNumber numberWithInteger:SSPublishContentMediaTypeNews]
                                          content:content
                                            title:title
                                              url:callBackUrlString
                                       thumbImage:nil
                                            image:[ShareSDK imageWithUrl:pngImageUrlString]
                                     musicFileUrl:nil
                                          extInfo:nil
                                         fileData:nil
                                     emoticonData:nil];
    
    //定制QQ分享信息
    [publishContent addQQUnitWithType:[NSNumber numberWithInteger:SSPublishContentMediaTypeNews]
                              content:content
                                title:title
                                  url:callBackUrlString
                                image:[ShareSDK imageWithUrl:pngImageUrlString]];
    
    //定制短信信息
    NSString *message = nil;
    if (content.length > 121) {
        message = [content substringToIndex:120];
    }
    else
    {
        message = content;
    }
    [publishContent addSMSUnitWithContent:[NSString stringWithFormat:@"%@..更多看这里:\r\n%@", message, callBackUrlString]];
//    [publishContent addSMSUnitWithContent:[NSString stringWithFormat:@"%@\r\n%@", content,callBackUrlString]
//                                  subject:title
//                              attachments:@[[ShareSDKCoreService attachmentWithUrl:callBackUrlString]]
//                                       to:@[@"15011991178"]];

    
    NSArray *shareList = [ShareSDK getShareListWithType:
                          
                          ShareTypeWeixiSession,
                          
                          ShareTypeWeixiTimeline,
                          
                          ShareTypeQQ,
                          
                          ShareTypeQQSpace,
                          
                          ShareTypeSinaWeibo,
                          
                          ShareTypeMail,
                          
                          ShareTypeSMS,
                          
                          ShareTypeCopy,
                          
                          nil];
    
    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
    
    //弹出分享菜单
    return [ShareSDK showShareActionSheet:container
                         shareList:shareList
                           content:publishContent
                     statusBarTips:YES
                       authOptions:nil
                      shareOptions:nil
                            result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                
                                if (state == SSResponseStateSuccess)
                                {
//                                    [ShowLoading showSuccView:sender message:@"分享成功!"];
                                }
                                else if (state == SSResponseStateFail)
                                {
//                                    NSLog(NSLocalizedString(@"TEXT_ShARE_FAI", @"分享失败,错误码:%d,错误描述:%@"), [error errorCode], [error errorDescription]);
//                                    [ShowLoading showSuccView:sender message:[NSString stringWithFormat:@"分享失败, 错误描述:%@", [error errorDescription]]];
                                }
                            }];
}

@end
